package com.eight.paper.admin.domain.model.enums;

import java.util.HashMap;
import java.util.Map;


public enum QuestionTypeEnum {

    SingleChoice("0", "单选题"),
    MultipleChoice("1", "多选题"),
    GapFilling("2", "填空题"),
    Explain("3", "名词解释"),
    ShortAnswer("4", "简答题"),
    Analysis("5", "分析题"),
    Discuss("6", "论述题"),
    B1("7", "B1配伍题"),
    A3A4Single("8", "A3A4单选题"),
    A3A4Multiple("9", "A3A4多选题"),
    TrueFalse("10", "判断题"),
    IMAGE("11", "影像题");

    String code;
    String name;

    QuestionTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }


    private static final Map<String, QuestionTypeEnum> keyMap = new HashMap<>();

    static {
        for (QuestionTypeEnum item : QuestionTypeEnum.values()) {
            keyMap.put(item.getCode(), item);
        }
    }

    public static QuestionTypeEnum fromCode(String code) {
        return keyMap.get(code);
    }

    public static QuestionTypeEnum fromName(String name) {
        for (QuestionTypeEnum item : QuestionTypeEnum.values()) {
            if(item.getName().equals(name)){
                return item;
            }
        }
        return null;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
